package com.xue.springboot001.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String hello(){
        return "Hello, SpringBoot2";
    }

    @RequestMapping(value = "/user",method = RequestMethod.GET)
    public String getUser(){
        return "GET-张三";
    }

    @RequestMapping(value = "/user",method = RequestMethod.POST)
    public String saveUser(){
        return "POST-张三";
    }


    @RequestMapping(value = "/user",method = RequestMethod.PUT)
    public String putUser(){
        return "PUT-张三";
    }

    @RequestMapping(value = "/user",method = RequestMethod.DELETE)
    public String deleteUser(){
        return "DELETE-张三";
    }

    @GetMapping("/car/{id}/{username}")
    public Map<String,Object> getCar(
            @PathVariable("id") Integer id,
            @PathVariable("username") String username,
            @PathVariable Map<String,String> pv,
            @RequestHeader("User-agent")String userAgent,
            @RequestHeader Map<String ,String> header,
            @RequestParam("age") Integer age,
            @RequestParam("inters")List<String> inters,
            @RequestParam Map<String,String> params,
            @CookieValue(value = "_ga",required = false) String _ga
            ){

        Map<String ,Object> map = new HashMap<>();
//        map.put("id",id);
//        map.put("username",username);
//        map.put("header",header);
        map.put("age",age);
        map.put("inters",inters);
        map.put("param",params);
        map.put("_ga",_ga);
        return map;
    }

    @GetMapping("/hello1")
    public String hello1(@CookieValue(value = "JSESSIONID",required = false)String JSessionId){
        System.out.println(JSessionId);
        return "Hello";
    }

    @PostMapping("/postMethod")
    public Map<String,Object> postMethod(@RequestBody String content){
        Map<String,Object> map = new HashMap<>();
        map.put("content",content);
        return map;
    }

}
